/**
 * Created by lx on 17/6/5.
 */
var Hash = (function() {
    var hashrouter = {};
    function hashchange() {
        var url = window.location.hash;
        url = url.replace(/^#/i, '');
        if (url && url in hashrouter) {
            hashrouter[url].forEach(function(hook) {
                hook(url);
            })
        }
    }
    window.addEventListener("hashchange", function() {
        hashchange();
    });
    function main() {
        this.addrouter = function(url, hook) {
            if (url in hashrouter) {
                hashrouter[url].push(hook);
            } else {
                hashrouter[url] = [hook];
            }
        }
        this.refresh = function() {
            hashchange();
        }
    }
    return main;
})();